package com.example.lenovo.newgift.home.channel;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.lenovo.newgift.entity.ChannelItemData;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Risky57 on 2017/6/28.
 */

public class ChannelAdapter extends BaseAdapter {

    private List<ChannelItemData.ItemEntity> data;
    private LayoutInflater mInflater;
    private Context mContext;

    public ChannelAdapter (Context context) {
        mContext = context;
        data = new ArrayList<>();
        mContext = context;
        mInflater = LayoutInflater.from(context);
    }

    public void addAll(List<ChannelItemData.ItemEntity> data){
        this.data.clear();
        this.data.addAll(data);
        notifyDataSetChanged();
    }

    @Override
    public int getCount () {
        return data.size();
    }

    @Override
    public Object getItem (int position) {
        return data.get(position);
    }

    @Override
    public long getItemId (int position) {
        return 0;
    }

    @Override
    public View getView (int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = mInflater.inflate(android.R.layout.simple_list_item_1, parent, false);
        }
        TextView textView = (TextView) convertView;
        textView.setText(data.get(position).getAuthor().getNickname());
        return convertView;
    }
}
